// 获取元素
const tab_nav = document.querySelector('.tab-nav')
const tab_pane = document.querySelectorAll('.tab-pane')
// 当登入方式被点击 切换 显示
tab_nav.addEventListener('click', function (e) {
    if (e.target.tagName === 'A') {
        // 取消上一个 active
        tab_nav.querySelector('.active').classList.remove('active')
        //当前元素添加 active
        e.target.classList.add('active')
        //干掉所有
        for (let i = 0; i < tab_pane.length; i++) {
            tab_pane[i].style.display = 'none'
        }
        //让对应的序号显示
        tab_pane[e.target.dataset.id].style.display = 'block'
    }

})

const form = document.querySelector('form')
const agree = document.getElementById('agree_input')
const nickname = document.getElementById('nickname_input')
const uname = document.getElementById('username_input')
const password = document.getElementById('password_input')
// 提交表单事件 登入跳转
form.addEventListener('submit', function (e) {
    //阻止默认事件
    e.preventDefault()
    if (!agree.checked) {
        return alert('请勾选用户协议')
    }
    register(nickname.value,uname.value,password.value).then(
        (data) => {
            location.href = '../../index.html'
            // location.href = '/index.html'
        }
    ).catch(
        (data)=>{
            alert(data)
        }
    )
    //记录用户名到本地存储
    // localStorage.setItem('username', uname.value)
    //跳转
    // location.href = '/index.html'
})
// 注册按钮 跳转
regist.addEventListener('click', function (e) {
    //阻止默认事件
    e.preventDefault()
    //跳转
    location.href = '../../regist.html'
    // location.href = '/pop/index.html'
})
